import sys

class Solution:
    def do_loop(self, works, mappings):
        keys = set([m[0] for m in mappings])
        mapping_kv = {k: [m[1] for m in mappings if m[0] == k] for k in keys}
        times = [0] * len(works)
        now_time = 0
        while True:
            if all([t != 0 for t in times]):
                break
            for i in range(len(works)):
                if times[i] == 0:
                    if i not in mapping_kv or all([times[ei] != 0 for ei in mapping_kv[i]]):
                        now_time += works[i]
                        times[i] = now_time
        return times

if __name__ == "__main__":
    # get map from input
    fp = sys.stdin
    line = fp.readline().split(',')
    works = [int(e) for e in line]
    line = fp.readline().split(',')
    mappings = []
    for mapping in line:
        a, b = mapping.split('->')
        mappings.append((int(a), int(b)))

    s = Solution()
    times = s.do_loop(works, mappings)
    print(','.join([str(t) for t in times]))
